package com.atguigu.flink.sql;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.descriptors.Csv;
import org.apache.flink.table.descriptors.FileSystem;
import org.apache.flink.table.descriptors.Schema;

/**
 * Created by Smexy on 2023/3/4
 *
 *  读取一个文件，将文件中的数据映射为 Table
 */
public class Demo2_ReadFile
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnvironment = StreamTableEnvironment.create(env);

        //使用create语句创建表，映射文件系统中指定的数据
        String createTableSql = " create table t1 ( id string,ts bigint, vc int  )" +
                                " with ( " +
                                 " 'connector' = 'filesystem' ,   " +
                                 " 'path' =  'data/cep.txt' ,   " +
                                 "  'format' = 'csv' " +
                                 "      )                 ";

        //执行建表
        tableEnvironment.executeSql(createTableSql);

        tableEnvironment.sqlQuery("select * from t1")
                        .execute()
                        .print();


    }
}
